package com.zp.base.admin.security;

import com.alibaba.fastjson.JSON;
import com.zp.base.admin.common.aspect.AddOperatorLog;
import com.zp.base.admin.common.utils.R;
import com.zp.base.admin.entity.UserEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author zhangpeng
 * @create 2020/8/27 17:26
 */
@Component
@Slf4j
public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
    @Override
    @AddOperatorLog(content = "登录后台系统")
    public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        log.info ("onAuthenticationSuccess ....");

        String jsonStr = JSON.toJSONString (R.ok());
        httpServletResponse.setContentType ("application/json;charset=utf-8");
        httpServletResponse.getOutputStream ().print (jsonStr);
    }
}
